<?php
/* @var $this SiteController */

$this->pageTitle=Yii::app()->name;
?>

<h3>Bem Vindo!</h3>

<?php 

	$team = Team::model()->findByAttributes(array('owner_id' => $_SESSION['owner']->id));

	if($team != null) {
		
		$pendentes = array();
		$transations = array();
		
		if($team->categories != null && count($team->categories) > 0) { 
			
			foreach ( $team->categories as $category ) {
				foreach ( $category->players as $player ) {
					$history = History::model()->findByAttributes(array('player'=>$player->id,'year'=>date('Y')));
					if($history == null) {
						$pendentes[] = $player;
					}
					
					$selling = Transference::model()->findByAttributes(array('player'=>$player->id, 'status' => 'EM ANDAMENTO'));
					if($selling != null) {
						$transations[] = $selling; 
					}
				}
			}
			
		}
		
		$buying = Transference::model()->findAllByAttributes(array('team_buyer_id'=>$team->id,'status' => 'EM ANDAMENTO'));
		if($buying != null && count($buying) > 0) {
			foreach($buying as $transfer) {
				$transations[] = $transfer;
			}
		}
		
?> 

<?php if($pendentes != null && count($pendentes) > 0) { ?>
 
<div class="view span9" style="overflow: auto; max-height: 145px;">
<h3 align="center">Revalidações Pendentes</h3>
<?php foreach($pendentes as $pendente) { 
	$photo = Utils::getPlayerPhoto ( $pendente );?>

	<span class="span1">
	<a href='<?php echo Yii::app ()->getBaseUrl ( true ); ?>/index.php/player/view/<?php echo $player->id; ?>'>
				
	<img src="<?php echo Utils::findImageUrl ( $photo [0]->filename ); ?>" style="width:100px; height:150xp;" />
	<p align="center"><?php echo $pendente->nickname;?></p>
	</a>
	</span>

<?php } ?>
</div>
<?php } ?>

<?php if($transations != null && count($transations) > 0) { ?>
<div class="view span9" style="overflow: auto; max-height: 200px;">
<h3 align="center">Transferências Pendentes</h3>
	<?php foreach($transations as $transation) {
		 $player = $transation->player0;
		 $photo = Utils::getPlayerPhoto ( $player );
		 $team_photo = null;
		 if($team->id == $transation->team_buyer_id) {
		 	$team_photo = Utils::getTeamPhoto( $transation->teamOwner);
		 } else {
		 	$team_photo = Utils::getTeamPhoto( $transation->teamBuyer);
		 }?>
		 
	<span class="span4">
	<a href='<?php echo Yii::app ()->getBaseUrl ( true ); ?>/index.php/transference/view/<?php echo $transation->id; ?>'>
	<table>
	<tr>			
	<td><img src="<?php echo Utils::findImageUrl ( $photo [0]->filename ); ?>" style="width:100px; height:150xp;" />=>
	<img src="<?php echo Utils::findImageUrl ( $team_photo [0]->filename ); ?>" style="width:100px; height:150xp;" /></td></tr>
	<tr><td>
	<?php if($team->id == $transation->team_buyer_id) {?>
		<p align="center"><?php echo 'Compra:'. $player->nickname. ' | Clube: '. $transation->teamOwner->name . ' | Preço: ' . $transation->price.',00 R$';?></p>
	<?php } else { ?>
		<p align="center"><?php echo 'Venda:'. $player->nickname. ' | Clube: '. $transation->teamBuyer->name . ' | Preço: ' . $transation->price .',00 R$';?></p>
		
		 <?php }?>
	</td></tr>
	</table>
	</a>
	</span>
		 
	<?php } ?>
	
<?php }?>

</div>

<?php } ?>

